<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加菜单</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
</head>
<body style="padding:10px 0px;">
	<form class="layui-form">
		
		<input type="hidden" name="pid" value="{$parent_menu.menu_id}">
		<?php if($pid) {?>
		<div class="layui-form-item">
			<label class="layui-form-label">上级菜单</label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input" name="pid" value="{$parent_menu.title}" disabled = "true">
			</div>
		</div>
		<?php }?>
		<div class="layui-form-item">
			<label class="layui-form-label">菜单名称</label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input" name="title" value="{$edit.title}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-inline">
                <input type="text" class="layui-input" name="ord" value="{$edit.ord}">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">控制器</label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input" name="controller" value="{$edit.controller}">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">方法</label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input" name="method" value="{$edit.method}">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
                <input type="checkbox" name="ishidden" lay-skin="primary" title="是否隐藏" class="layui-input-block" value="{$edit.ishidden}">
                <input type="checkbox" name="status" lay-skin="primary" title="是否禁用" class="layui-input-block" value="{$edit.status}">
			</div>
        </div>
        
	</form>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" onclick="save()">保存</button>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	layui.use(['layer','form'],function(){
		var form = layui.form;
		layer = layui.layer;
		$ = layui.jquery;
	});

	function save(){
		var pid = parseInt($('input[name="pid"]').val());
        var title = $.trim($("input[name='title']").val());
        var controller = $.trim($("input[name='controller']").val());
        var method = $.trim($("input[name='method']").val());
        var ord = parseInt($("input[name='ord']").val());

		if(title==''){
			layer.alert('请输入菜单名',{'icon':2});
			return;
		}
		if(controller == ''){
			layer.alert('请输入控制器名',{'icon':2});
			return;
		}
		if(method==''){
			layer.alert('请输入方法名',{'icon':2});
			return;
		}
        $.ajax({
            type:'post',
            url:'{:url(\'Menu/save\')}',
            dataType:'json',
            data:$('form').serialize(),
            success:function(res){
                console.log(res);
                if(res.code == 1){
                    layer.alert(res.msg,{icon:2});
                }else{
                    layer.msg(res.msg,{icon:1});
                    setTimeout(function(){parent.window.location.reload();},1000);
                }
            }
        })
	}
</script>
